﻿using ShortcutMenu.Hooks;
using ShortcutMenu.Render;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ShortcutMenu.Manager
{
    public class HookManager : ManagerBase
    {
        private Dictionary<Type, HookBase> _hookBase = new();

        public HookManager()
        {
            var ass = Assembly.GetAssembly(this.GetType())!.GetTypes();
            var main = MenuApplication.GetMainWondw();
            _hookBase = Reflection.Create<HookBase>(ass, main);
        }

        public override void initialize()
        {
            #region 开启钩子
            var readerM = MenuApplication.GetManager<ReaderManager>();


            //桌面显示菜单
            GetHook<ViewDisplayHook>().HookStart(() =>
            {
                readerM.ShowWindow<DesktopRender>();
            });

            #endregion

        }


        public T GetHook<T>() where T : HookBase
        {
            return (_hookBase[typeof(T)] as T)!;
        }

        public List<HookBase> GetHook()
        {
            return _hookBase.GetValues();
        }


        /// <summary>
        /// 卸载所有钩子
        /// </summary>
        public void HookStopAll()
        {
            foreach (var hook in _hookBase)
            {
                hook.Value.HookStop();
            }
        }


    }
}
